﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Temperature
{
    public partial class TempView : Form, ITempView
    {
        private TempController _controller;
        private char _unit;

        public TempView(TempController controller)
        {
            InitializeComponent();
            _controller = controller;
            controller.RegisterView(this);
            _unit = controller.GetDefaultUnit();
            this.RefreshView();
        }

        public void SetUnit(char unit)
        {
            _unit = unit;
            this.RefreshView();
        }//end SetUnit

        public void SetTemp(double temp)
        {
            _controller.SetTemp(temp, _unit);
        }//end SetTemp

        public void RefreshView()
        {
            this.Text = "TempView in " + "°" + _unit;
            this.txtTempDisplay.Text = _controller.GetTemp(_unit).ToString("F2") + "°" + _unit;
        }

        private void btnDecrement_Click(object sender, EventArgs e)
        {
            _controller.SetTemp(_controller.GetTemp(_unit) - 1, _unit);
        }

        private void btnIncrement_Click(object sender, EventArgs e)
        {
            _controller.SetTemp(_controller.GetTemp(_unit) + 1, _unit);
        }//end Refresh

    }
}
